import os

import cv2
from tqdm import tqdm

from option import parse_args

if __name__ == '__main__':
    args = parse_args()
    # diffs = os.path.join(args.root_dir, 'diffs')
    # fake_crops = os.path.join(args.root_dir, 'manipulated_sequences', args.fake_type, 'c23', 'crops')
    crops, version = args.crops_dir, args.compression_version
    original_crops = os.path.join(args.root_dir, 'original_sequences', 'youtube', version, crops)
    videos = open(f'abnormal_width_statistics_{version}.dat').readlines()
    for video_name in tqdm(videos):
        video_split = video_name.split(',')
        assert len(video_split) == 3
        video_path = os.path.join(original_crops, video_split[0])
        max_width = int(video_split[2].strip())
        for crop in os.listdir(video_path):
            img = cv2.imread(os.path.join(video_path, crop), cv2.IMREAD_GRAYSCALE)
            diff = max_width - img.shape[1]
            if img.shape[1] < 100 and diff > 50:
                os.remove(os.path.join(video_path, crop))
